package com.softtek.ibeacon.service.sys;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;

import com.softtek.ibeacon.bo.EmployeeBO;
import com.softtek.ibeacon.common.ServiceException;
import com.softtek.ibeacon.entity.Employee;
import com.softtek.ibeacon.entity.Hardware;
import com.softtek.ibeacon.entity.Storeinfo;
import com.softtek.ibeacon.service.BaseServiceImpl;

public class StoreServiceImpl extends BaseServiceImpl implements StoreService {

	@SuppressWarnings("unchecked")
	public Map<String, List<Storeinfo>> getStoreList(int firstResult, int maxResult) {
		return (Map<String, List<Storeinfo>>) dao.queryBySql2Entity("select * from Storeinfo", null, Storeinfo.class, 0,
				5);
	}

	@Override
	public EmployeeBO login(String employNumber, String password) {
		Employee em = (Employee) dao.queryForObject("select * from employee where employeenumber=? and password=?",
				new Object[] { employNumber, password }, new BeanPropertyRowMapper<Employee>(Employee.class));
		if (em == null) {
			return null;
		}
		return getEmpBo(em);
	}
	
	private  EmployeeBO getEmpBo(Employee em){
		EmployeeBO bo = new EmployeeBO();
		bo.setEmployee(em);
		bo.setHardware((Hardware) dao.findById(Hardware.class, em.getHardwareId()));
		bo.setStoreinfo((Storeinfo) dao.findById(Storeinfo.class, em.getStoreId()));
		return bo;
	}
	
	

}
